package com.itheima.work;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @auther Macrydy
 * @date 2020/7/7 18:15
 */
public class Test1 {
    public static void main(String[] args) {
//        threadDemo td= new threadDemo();
//        td.start();
//        for (int k = 0; k < 100; k++) {
//            System.out.println(k);
//        }
//
//        runnableDemo rb = new runnableDemo();
//        Thread thread = new Thread(rb);
//        thread.start();

//        DateThread dt = new DateThread();
//        dt.start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                int sum = getSum(100);
                System.out.println(Thread.currentThread().getName() + "线程计算1--100的累加和，结果：" + sum);
            }

        }).start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                int sum = getSum(1000);
                System.out.println(Thread.currentThread().getName() + "线程计算1--1000的累加和，结果：" + sum);
            }

        }).start();

    }
    public static int getSum(int i){
        if (i == 1) {
            return 1;
        } else {
            return i + getSum(i - 1);
        }
    }
}

class threadDemo extends Thread {
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(i);
        }
    }
}

class runnableDemo implements Runnable {

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(i);
        }
    }
}

class DateThread extends Thread {
    @Override
    public void run() {
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        for (int i = 0; i < 10; i++) {
            Date date = new Date();
            System.out.println(sf.format(date));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

class ThreadDemo2 extends Thread {
    @Override
    public void run() {
        super.run();
    }


}